{
  "name": "Case 54: Visa Expiry & Compliance Agent - Intelligent Agent",
  "nodes": [
    {
      "parameters": {
        "path": "visa-upload-form",
        "formTitle": "Visa/Work Permit Document Upload",
        "formDescription": "Upload your visa or work permit document for automated compliance tracking",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Upload Visa/Passport Document",
              "fieldType": "file",
              "requiredField": true
            }
          ]
        },
        "options": {}
      },
      "id": "8381b57f-39e4-47a6-8b94-f8ee1bcab2c3",
      "name": "Visa Upload Form",
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.1,
      "position": [
        -1232,
        -16
      ],
      "webhookId": "visa-upload-form"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.cloud.llamaindex.ai/api/v1/parsing/upload",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer llx-7BWYrvPwfUhgdXbZMtaNCsr2O0h7JH4dkHjHisxcvq46bkIj"
            }
          ]
        },
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": {
          "parameters": [
            {
              "parameterType": "formBinaryData",
              "name": "file",
              "inputDataFieldName": "Upload_Visa_Passport_Document"
            }
          ]
        },
        "options": {}
      },
      "id": "2c975617-9371-4d35-b972-7d31c4de8dec",
      "name": "Upload Visa Document",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        -1024,
        -16
      ]
    },
    {
      "parameters": {
        "amount": 20
      },
      "id": "5d249f23-2f2d-4d11-9873-1bf278e947c9",
      "name": "Wait for Parsing",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        -832,
        -16
      ],
      "webhookId": "e7190430-99fa-40a0-bd07-1e74289ebc60"
    },
    {
      "parameters": {
        "url": "=https://api.cloud.llamaindex.ai/api/v1/parsing/job/{{ $node[\"Upload Visa Document\"].json[\"id\"] }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer llx-7BWYrvPwfUhgdXbZMtaNCsr2O0h7JH4dkHjHisxcvq46bkIj"
            }
          ]
        },
        "options": {}
      },
      "id": "e1dc884f-18e2-4e53-a565-4aff81ff745e",
      "name": "Check Parsing Status",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        -624,
        -16
      ]
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "conditions": [
                  {
                    "leftValue": "={{ $json.status }}",
                    "rightValue": "SUCCESS",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ]
              },
              "renameOutput": true,
              "outputKey": "SUCCESS"
            },
            {
              "conditions": {
                "conditions": [
                  {
                    "leftValue": "={{ $json.status }}",
                    "rightValue": "PENDING",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ]
              },
              "renameOutput": true,
              "outputKey": "PENDING"
            }
          ]
        },
        "options": {}
      },
      "id": "a5ab7c74-509d-4777-aca4-0856360b468d",
      "name": "Status Router",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.3,
      "position": [
        -432,
        -16
      ]
    },
    {
      "parameters": {
        "url": "=https://api.cloud.llamaindex.ai/api/v1/parsing/job/{{ $node[\"Upload Visa Document\"].json[\"id\"] }}/result/markdown",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer llx-7BWYrvPwfUhgdXbZMtaNCsr2O0h7JH4dkHjHisxcvq46bkIj"
            }
          ]
        },
        "options": {}
      },
      "id": "afd9d4dd-dbf9-4e4e-8eef-7ceb4d165322",
      "name": "Get Parsed Visa Data",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        -224,
        -128
      ]
    },
    {
      "parameters": {
        "text": "={{ $json.markdown }}",
        "attributes": {
          "attributes": [
            {
              "name": "Employee_Name",
              "description": "Full name from document"
            },
            {
              "name": "Employee_ID",
              "description": "Company employee ID"
            },
            {
              "name": "Department",
              "description": "Department name"
            },
            {
              "name": "Job_Title",
              "description": "Job title or position"
            },
            {
              "name": "Employee_Email",
              "description": "Email address"
            },
            {
              "name": "Passport_Number",
              "description": "Passport number"
            },
            {
              "name": "Nationality",
              "description": "Country of citizenship"
            },
            {
              "name": "Passport_Issue_Date",
              "description": "Passport issue date in YYYY-MM-DD"
            },
            {
              "name": "Passport_Expiry_Date",
              "description": "Passport expiry date in YYYY-MM-DD"
            },
            {
              "name": "Visa_Type",
              "description": "Type of visa (H-1B, L-1, Work Permit, etc.)"
            },
            {
              "name": "Visa_Country",
              "description": "Country where visa is valid"
            },
            {
              "name": "Visa_Number",
              "description": "Unique visa number"
            },
            {
              "name": "Visa_Issue_Date",
              "description": "Visa issue date in YYYY-MM-DD"
            },
            {
              "name": "Visa_Expiry_Date",
              "description": "Visa expiry date in YYYY-MM-DD - CRITICAL FIELD"
            },
            {
              "name": "Current_Status",
              "description": "Active / Expired / Pending"
            },
            {
              "name": "Work_Location",
              "description": "Authorized work location"
            },
            {
              "name": "Sponsoring_Employer",
              "description": "Company sponsoring the visa"
            },
            {
              "name": "Submission_Date",
              "description": "Date document was submitted to HR in YYYY-MM-DD"
            }
          ]
        },
        "options": {}
      },
      "id": "a9a47a49-33cf-45a4-831a-1cc17e424053",
      "name": "Extract Visa Data",
      "type": "@n8n/n8n-nodes-langchain.informationExtractor",
      "typeVersion": 1.2,
      "position": [
        -32,
        -128
      ]
    },
    {
      "parameters": {
        "jsCode": "const extracted = $node[\"Extract Visa Data\"].json.output || {};\nconst formData = $node[\"Visa Upload Form\"].json || {};\n\n// ===== COMPANY COMPLIANCE RULES (HARDCODED) =====\n\nconst COMPLIANCE_THRESHOLDS = {\n  CRITICAL: 30,   // 0-30 days\n  HIGH: 60,       // 31-60 days\n  MEDIUM: 90,     // 61-90 days\n  LOW: 999999     // 90+ days\n};\n\nconst VISA_RENEWAL_LEAD_TIME = {\n  'H-1B': 90,           // US H-1B needs 90 days\n  'L-1': 90,            // US L-1 needs 90 days\n  'E-2': 120,           // US E-2 needs 120 days\n  'Work Permit': 60,    // Generic work permit\n  'Skilled Worker': 90, // UK Skilled Worker\n  'Default': 90         // Default for unknown types\n};\n\nconst EMPLOYEE_ROLE_CRITICALITY = {\n  'Senior': 30,\n  'Lead': 25,\n  'Manager': 30,\n  'Director': 35,\n  'VP': 40,\n  'Default': 20\n};\n\n// ===== EXTRACT AND PARSE DATA =====\n\nconst visaExpiryDate = extracted.Visa_Expiry_Date || '';\nconst visaType = extracted.Visa_Type || 'Default';\nconst jobTitle = (extracted.Job_Title || '').toLowerCase();\nconst submissionDate = extracted.Submission_Date || new Date().toISOString().split('T')[0];\n\n// ===== CALCULATE DAYS TO EXPIRY =====\n\nlet daysToExpiry = 999999;\nif (visaExpiryDate) {\n  const today = new Date();\n  const expiry = new Date(visaExpiryDate);\n  daysToExpiry = Math.floor((expiry - today) / (1000 * 60 * 60 * 24));\n}\n\n// ===== DETERMINE RISK LEVEL =====\n\nlet riskLevel = 'LOW';\nlet urgencyScore = 0;\n\nif (daysToExpiry <= COMPLIANCE_THRESHOLDS.CRITICAL) {\n  riskLevel = 'CRITICAL';\n  urgencyScore = 40;\n} else if (daysToExpiry <= COMPLIANCE_THRESHOLDS.HIGH) {\n  riskLevel = 'HIGH';\n  urgencyScore = 30;\n} else if (daysToExpiry <= COMPLIANCE_THRESHOLDS.MEDIUM) {\n  riskLevel = 'MEDIUM';\n  urgencyScore = 20;\n} else {\n  riskLevel = 'LOW';\n  urgencyScore = 10;\n}\n\n// ===== COMPLIANCE SCORE CALCULATION (0-100) =====\n\nlet complianceScore = 0;\n\n// 1. Days to Expiry Urgency (40 points)\ncomplianceScore += urgencyScore;\n\n// 2. Visa Type Complexity (30 points)\nconst renewalLeadTime = VISA_RENEWAL_LEAD_TIME[visaType] || VISA_RENEWAL_LEAD_TIME.Default;\nif (daysToExpiry < renewalLeadTime) {\n  complianceScore += 30; // Urgent - within renewal window\n} else if (daysToExpiry < renewalLeadTime * 1.5) {\n  complianceScore += 15; // Approaching renewal window\n}\n\n// 3. Employee Role Criticality (20 points)\nlet roleCriticality = EMPLOYEE_ROLE_CRITICALITY.Default;\nfor (const [role, points] of Object.entries(EMPLOYEE_ROLE_CRITICALITY)) {\n  if (jobTitle.includes(role.toLowerCase())) {\n    roleCriticality = points;\n    break;\n  }\n}\ncomplianceScore += roleCriticality;\n\n// 4. Passport Expiry Check (10 points)\nconst passportExpiry = extracted.Passport_Expiry_Date || '';\nif (passportExpiry) {\n  const passExpiry = new Date(passportExpiry);\n  const passportDays = Math.floor((passExpiry - new Date()) / (1000 * 60 * 60 * 24));\n  if (passportDays < 180) {\n    complianceScore += 10; // Passport also expiring soon\n  }\n}\n\n// Cap at 100\ncomplianceScore = Math.min(complianceScore, 100);\n\n// ===== RENEWAL URGENCY =====\n\nlet renewalUrgency = '';\nif (complianceScore >= 75) {\n  renewalUrgency = 'IMMEDIATE_ACTION_REQUIRED';\n} else if (complianceScore >= 50) {\n  renewalUrgency = 'START_RENEWAL_PROCESS';\n} else if (complianceScore >= 30) {\n  renewalUrgency = 'PREPARE_DOCUMENTS';\n} else {\n  renewalUrgency = 'ROUTINE_MONITORING';\n}\n\n// ===== RECOMMENDED ACTIONS =====\n\nlet recommendedAction = '';\nlet alertSentTo = '';\nlet nextReviewDate = '';\n\nif (riskLevel === 'CRITICAL') {\n  recommendedAction = `URGENT: Visa expires in ${daysToExpiry} days. Immediate renewal required. Escalate to legal team and immigration counsel. Employee may need to stop work if not renewed.`;\n  alertSentTo = 'HR + Legal + Employee + Manager';\n  const reviewDate = new Date();\n  reviewDate.setDate(reviewDate.getDate() + 7);\n  nextReviewDate = reviewDate.toISOString().split('T')[0];\n} else if (riskLevel === 'HIGH') {\n  recommendedAction = `High Priority: Visa expires in ${daysToExpiry} days. Start renewal process immediately. Assign immigration case manager. Prepare all required documents.`;\n  alertSentTo = 'HR + Employee + Manager';\n  const reviewDate = new Date();\n  reviewDate.setDate(reviewDate.getDate() + 14);\n  nextReviewDate = reviewDate.toISOString().split('T')[0];\n} else if (riskLevel === 'MEDIUM') {\n  recommendedAction = `Medium Priority: Visa expires in ${daysToExpiry} days. Send renewal reminder to employee. Begin document collection process.`;\n  alertSentTo = 'HR + Employee';\n  const reviewDate = new Date();\n  reviewDate.setDate(reviewDate.getDate() + 30);\n  nextReviewDate = reviewDate.toISOString().split('T')[0];\n} else {\n  recommendedAction = `Low Priority: Visa expires in ${daysToExpiry} days. Routine monitoring. Quarterly compliance check scheduled.`;\n  alertSentTo = 'HR Only';\n  const reviewDate = new Date();\n  reviewDate.setDate(reviewDate.getDate() + 90);\n  nextReviewDate = reviewDate.toISOString().split('T')[0];\n}\n\n// ===== STATUS DETERMINATION =====\n\nlet status = 'ACTIVE';\nif (daysToExpiry < 0) {\n  status = 'EXPIRED';\n} else if (daysToExpiry <= 30) {\n  status = 'EXPIRING_SOON';\n} else if (daysToExpiry <= 90) {\n  status = 'RENEWAL_DUE';\n} else {\n  status = 'ACTIVE';\n}\n\n// ===== RETURN STRUCTURED DATA =====\n\nreturn {\n  Employee_Name: extracted.Employee_Name || 'NOT_FOUND',\n  Employee_ID: extracted.Employee_ID || 'NOT_FOUND',\n  Passport_Number: extracted.Passport_Number || 'NOT_FOUND',\n  Visa_Type: visaType,\n  Visa_Country: extracted.Visa_Country || 'NOT_FOUND',\n  Issue_Date: extracted.Visa_Issue_Date || 'NOT_FOUND',\n  Expiry_Date: visaExpiryDate || 'NOT_FOUND',\n  Days_To_Expiry: daysToExpiry,\n  Risk_Level: riskLevel,\n  Compliance_Score: complianceScore,\n  Renewal_Urgency: renewalUrgency,\n  Recommended_Action: recommendedAction,\n  Alert_Sent_To: alertSentTo,\n  Next_Review_Date: nextReviewDate,\n  Status: status,\n  \n  // Pass through for email\n  _full_visa_data: extracted,\n  _form_data: formData,\n  _employee_email: extracted.Employee_Email || 'employee@company.com',\n  _days_to_expiry: daysToExpiry,\n  _compliance_score: complianceScore\n};"
      },
      "id": "e6b26aed-b06c-4206-b3d0-f87bb9fe5b2a",
      "name": "Compliance Risk Engine",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        272,
        -128
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1HZkN9glDxcE6_Bnl8K2QS9gVbG_chr6oe_QLV2gdaxY",
          "mode": "list",
          "cachedResultName": "Case 54 - Visa Expiry Documents Log",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1HZkN9glDxcE6_Bnl8K2QS9gVbG_chr6oe_QLV2gdaxY/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1HZkN9glDxcE6_Bnl8K2QS9gVbG_chr6oe_QLV2gdaxY/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Employee_Name": "={{ $json.Employee_Name }}",
            "Employee_ID": "={{ $json.Employee_ID }}",
            "Passport_Number": "={{ $json.Passport_Number }}",
            "Visa_Type": "={{ $json.Visa_Type }}",
            "Visa_Country": "={{ $json.Visa_Country }}",
            "Issue_Date": "={{ $json.Issue_Date }}",
            "Expiry_Date": "={{ $json.Expiry_Date }}",
            "Days_To_Expiry": "={{ $json.Days_To_Expiry }}",
            "Risk_Level": "={{ $json.Risk_Level }}",
            "Compliance_Score": "={{ $json.Compliance_Score }}",
            "Renewal_Urgency": "={{ $json.Renewal_Urgency }}",
            "Recommended_Action": "={{ $json.Recommended_Action }}",
            "Alert_Sent_To": "={{ $json.Alert_Sent_To }}",
            "Next_Review_Date": "={{ $json.Next_Review_Date }}",
            "Status": "={{ $json.Status }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Employee_Name",
              "displayName": "Employee_Name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Employee_ID",
              "displayName": "Employee_ID",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Passport_Number",
              "displayName": "Passport_Number",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Visa_Type",
              "displayName": "Visa_Type",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Visa_Country",
              "displayName": "Visa_Country",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Issue_Date",
              "displayName": "Issue_Date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Expiry_Date",
              "displayName": "Expiry_Date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Days_To_Expiry",
              "displayName": "Days_To_Expiry",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Risk_Level",
              "displayName": "Risk_Level",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Compliance_Score",
              "displayName": "Compliance_Score",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Renewal_Urgency",
              "displayName": "Renewal_Urgency",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Recommended_Action",
              "displayName": "Recommended_Action",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Alert_Sent_To",
              "displayName": "Alert_Sent_To",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Next_Review_Date",
              "displayName": "Next_Review_Date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Status",
              "displayName": "Status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "id": "7a16c7d3-e97e-43ec-8511-5814a22853c0",
      "name": "Log to Compliance Database",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        464,
        -128
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "LOs2dbk9lby0NfDM",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.Risk_Level }}",
                    "rightValue": "CRITICAL",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "id": "3bd38fe6-08ec-4d20-a004-3c317359b837"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "CRITICAL_ALERT"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.Risk_Level }}",
                    "rightValue": "HIGH",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "id": "1876a624-d07b-47d0-8322-56c8359c7187"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "HIGH_ALERT"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "06486591-0a03-4cad-b1d0-decc2381e404",
                    "leftValue": "={{ $json.Risk_Level }}",
                    "rightValue": "MEDIUM",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "ROUTINE_REMINDER"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "f03d0d0b-babc-4af9-935a-275e46c7725d",
                    "leftValue": "={{ $json.Risk_Level }}",
                    "rightValue": "LOW",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "ROUTINE_REMINDER"
            }
          ]
        },
        "options": {
          "fallbackOutput": "none"
        }
      },
      "id": "b32dafc4-fc1d-4975-b03b-1376ff30c743",
      "name": "Risk Level Router",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.3,
      "position": [
        640,
        -128
      ]
    },
    {
      "parameters": {
        "jsCode": "const data = $input.first().json || {};\nconst visa = data._full_visa_data || {};\n\nconst emailSubject = `🚨 URGENT: Visa Expiring in ${data.Days_To_Expiry} Days | ${data.Employee_Name || 'Employee'}`;\nconst emailBody = `<html><body style=\"font-family:Arial,sans-serif;max-width:700px;margin:0 auto;padding:20px\"><div style=\"background:linear-gradient(135deg,#dc2626,#991b1b);color:white;padding:25px;border-radius:8px;margin-bottom:20px\"><h1 style=\"margin:0;font-size:24px\">🚨 CRITICAL: Visa Expiring Soon</h1><p style=\"margin:5px 0 0 0\">Employee: ${data.Employee_Name || 'N/A'}</p></div><div style=\"background:#fee2e2;border-left:4px solid #dc2626;padding:15px;margin:20px 0;border-radius:4px\"><strong>IMMEDIATE ACTION REQUIRED - Visa expires in ${data.Days_To_Expiry} days</strong></div><div style=\"background:#f9fafb;padding:20px;border-radius:8px;margin:20px 0\"><h2 style=\"margin:0 0 15px 0;font-size:18px\">Visa Details</h2><table style=\"width:100%\"><tr><td style=\"padding:8px 0;color:#6b7280\">Employee:</td><td style=\"padding:8px 0;font-weight:600\">${data.Employee_Name || 'N/A'} (${data.Employee_ID || 'N/A'})</td></tr><tr><td style=\"padding:8px 0;color:#6b7280\">Visa Type:</td><td style=\"padding:8px 0;font-weight:600\">${data.Visa_Type || 'N/A'}</td></tr><tr><td style=\"padding:8px 0;color:#6b7280\">Country:</td><td style=\"padding:8px 0\">${data.Visa_Country || 'N/A'}</td></tr><tr><td style=\"padding:8px 0;color:#6b7280\">Expiry Date:</td><td style=\"padding:8px 0;color:#dc2626;font-weight:700;font-size:18px\">${data.Expiry_Date || 'N/A'}</td></tr><tr><td style=\"padding:8px 0;color:#6b7280\">Days Remaining:</td><td style=\"padding:8px 0;color:#dc2626;font-weight:700;font-size:20px\">${data.Days_To_Expiry}</td></tr><tr><td style=\"padding:8px 0;color:#6b7280\">Compliance Score:</td><td style=\"padding:8px 0;color:#dc2626;font-size:18px\">${data.Compliance_Score || 0}/100</td></tr></table></div><div style=\"background:#eff6ff;border:2px solid #3b82f6;border-radius:8px;padding:20px;margin:20px 0\"><h3 style=\"margin:0 0 15px 0;color:#1e40af\">Required Actions</h3><p style=\"margin:0\">${data.Recommended_Action || 'Immediate renewal required'}</p></div><div style=\"background:#fef3c7;border:2px solid #f59e0b;border-radius:8px;padding:15px;margin:20px 0\"><strong>Alert Sent To:</strong> ${data.Alert_Sent_To || 'HR'}<br><strong>Next Review Date:</strong> ${data.Next_Review_Date || 'TBD'}</div></body></html>`;\n\nreturn {\n  emailSubject,\n  emailBody,\n  recipientEmail: data._employee_email || 'employee@company.com',\n  hrEmail: 'hr.immigration@company.com',\n  legalEmail: 'legal@company.com'\n};"
      },
      "id": "41376a2e-748c-48fb-8112-7586e265a787",
      "name": "Build Critical Alert",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1024,
        -336
      ]
    },
    {
      "parameters": {
        "jsCode": "const data = $input.first().json || {};\nconst visa = data._full_visa_data || {};\n\nconst emailSubject = `⚠️ Visa Renewal Required: ${data.Days_To_Expiry} Days | ${data.Employee_Name || 'Employee'}`;\nconst emailBody = `<html><body style=\"font-family:Arial,sans-serif;max-width:700px;margin:0 auto;padding:20px\"><div style=\"background:linear-gradient(135deg,#f59e0b,#d97706);color:white;padding:25px;border-radius:8px;margin-bottom:20px\"><h1 style=\"margin:0;font-size:24px\">⚠️ Visa Renewal Required</h1><p style=\"margin:5px 0 0 0\">Employee: ${data.Employee_Name || 'N/A'}</p></div><div style=\"background:#fef3c7;border-left:4px solid #f59e0b;padding:15px;margin:20px 0;border-radius:4px\"><strong>Start renewal process - Visa expires in ${data.Days_To_Expiry} days</strong></div><div style=\"background:#f9fafb;padding:20px;border-radius:8px;margin:20px 0\"><h2 style=\"margin:0 0 15px 0;font-size:18px\">Visa Details</h2><table style=\"width:100%\"><tr><td style=\"padding:8px 0;color:#6b7280\">Employee:</td><td style=\"padding:8px 0;font-weight:600\">${data.Employee_Name || 'N/A'}</td></tr><tr><td style=\"padding:8px 0;color:#6b7280\">Visa Type:</td><td style=\"padding:8px 0\">${data.Visa_Type || 'N/A'}</td></tr><tr><td style=\"padding:8px 0;color:#6b7280\">Expiry:</td><td style=\"padding:8px 0;font-weight:700\">${data.Expiry_Date || 'N/A'}</td></tr><tr><td style=\"padding:8px 0;color:#6b7280\">Days Left:</td><td style=\"padding:8px 0;font-weight:700;font-size:18px\">${data.Days_To_Expiry}</td></tr></table></div><div style=\"background:#eff6ff;border:2px solid #3b82f6;border-radius:8px;padding:20px;margin:20px0\"><h3 style=\"margin:0 0 15px 0;color:#1e40af\">Next Steps</h3><p style=\"margin:0\">${data.Recommended_Action || 'Begin renewal process'}</p></div></body></html>`;\n\nreturn {\n  emailSubject,\n  emailBody,\n  recipientEmail: data._employee_email || 'employee@company.com',\n  hrEmail: 'hr.immigration@company.com'\n};"
      },
      "id": "6ea32cc4-0cba-4028-aab7-dcc411a8b4b8",
      "name": "Build High Priority Alert",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1024,
        -112
      ]
    },
    {
      "parameters": {
        "jsCode": "const data = $input.first().json || {};\nconst visa = data._full_visa_data || {};\n\nconst emailSubject = `📋 Visa Status Update: ${data.Days_To_Expiry} Days Remaining | ${data.Employee_Name || 'Employee'}`;\nconst emailBody = `<html><body style=\"font-family:Arial,sans-serif;max-width:700px;margin:0 auto;padding:20px\"><div style=\"background:linear-gradient(135deg,#3b82f6,#1e40af);color:white;padding:25px;border-radius:8px;margin-bottom:20px\"><h1 style=\"margin:0;font-size:24px\">📋 Visa Status Update</h1><p style=\"margin:5px 0 0 0\">Employee: ${data.Employee_Name || 'N/A'}</p></div><div style=\"background:#dbeafe;border-left:4px solid #3b82f6;padding:15px;margin:20px 0;border-radius:4px\"><strong>Routine compliance check - Visa expires in ${data.Days_To_Expiry} days</strong></div><div style=\"background:#f9fafb;padding:20px;border-radius:8px;margin:20px 0\"><h2 style=\"margin:0 0 15px 0;font-size:18px\">Visa Information</h2><table style=\"width:100%\"><tr><td style=\"padding:8px 0;color:#6b7280\">Employee:</td><td style=\"padding:8px 0;font-weight:600\">${data.Employee_Name || 'N/A'}</td></tr><tr><td style=\"padding:8px 0;color:#6b7280\">Visa Type:</td><td style=\"padding:8px 0\">${data.Visa_Type || 'N/A'}</td></tr><tr><td style=\"padding:8px 0;color:#6b7280\">Expiry:</td><td style=\"padding:8px 0\">${data.Expiry_Date || 'N/A'}</td></tr><tr><td style=\"padding:8px 0;color:#6b7280\">Status:</td><td style=\"padding:8px 0;color:#059669;font-weight:600\">${data.Status || 'ACTIVE'}</td></tr></table></div><div style=\"background:#f0fdf4;border:2px solid #059669;border-radius:8px;padding:20px;margin:20px 0\"><h3 style=\"margin:0 0 10px 0;color:#047857\">Action Required</h3><p style=\"margin:0\">${data.Recommended_Action || 'No immediate action required'}</p></div></body></html>`;\n\nreturn {\n  emailSubject,\n  emailBody,\n  recipientEmail: data._employee_email || 'employee@company.com'\n};"
      },
      "id": "f5e60b9a-5266-48e0-b666-412bf3e70a1d",
      "name": "Build Routine Reminder",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1024,
        80
      ]
    },
    {
      "parameters": {
        "sendTo": "={{ $json.recipientEmail }}",
        "subject": "={{ $json.emailSubject }}",
        "message": "={{ $json.emailBody }}",
        "options": {
          "ccList": "={{ $json.hrEmail }},={{ $json.legalEmail }}"
        }
      },
      "id": "953f5f2a-21a5-4f48-ad40-91d5bcb9cf5c",
      "name": "Send Critical Alert",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        1296,
        -336
      ],
      "webhookId": "f42dfd02-b9c0-4920-b2d9-022942311ad3",
      "credentials": {
        "gmailOAuth2": {
          "id": "cyqCGWcggZNMcSOv",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "sendTo": "={{ $json.recipientEmail }}",
        "subject": "={{ $json.emailSubject }}",
        "message": "={{ $json.emailBody }}",
        "options": {
          "ccList": "={{ $json.hrEmail }}"
        }
      },
      "id": "77a077cb-d151-4e9e-a823-e033d4ce8ef6",
      "name": "Send High Priority Alert",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        1296,
        -112
      ],
      "webhookId": "7aa45702-8ef7-4f35-8546-2bfe43059ef4",
      "credentials": {
        "gmailOAuth2": {
          "id": "cyqCGWcggZNMcSOv",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "sendTo": "={{ $json.recipientEmail }}",
        "subject": "={{ $json.emailSubject }}",
        "message": "={{ $json.emailBody }}",
        "options": {}
      },
      "id": "15fb8e35-9586-46df-84b4-747d06001b6e",
      "name": "Send Routine Reminder",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        1296,
        80
      ],
      "webhookId": "903325a2-334f-4cb6-bb59-26507cc6b663",
      "credentials": {
        "gmailOAuth2": {
          "id": "cyqCGWcggZNMcSOv",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list"
        },
        "builtInTools": {},
        "options": {}
      },
      "id": "6e08ad0c-36e0-482a-8322-f2009cf99d14",
      "name": "GPT-4o Mini",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        -32,
        80
      ],
      "credentials": {
        "openAiApi": {
          "id": "ICwxUBbatsF2sDvy",
          "name": "OpenAi account"
        }
      }
    }
  ],
  "pinData": {},
  "connections": {
    "Visa Upload Form": {
      "main": [
        [
          {
            "node": "Upload Visa Document",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload Visa Document": {
      "main": [
        [
          {
            "node": "Wait for Parsing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait for Parsing": {
      "main": [
        [
          {
            "node": "Check Parsing Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Parsing Status": {
      "main": [
        [
          {
            "node": "Status Router",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Status Router": {
      "main": [
        [
          {
            "node": "Get Parsed Visa Data",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait for Parsing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Parsed Visa Data": {
      "main": [
        [
          {
            "node": "Extract Visa Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Visa Data": {
      "main": [
        [
          {
            "node": "Compliance Risk Engine",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Compliance Risk Engine": {
      "main": [
        [
          {
            "node": "Log to Compliance Database",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log to Compliance Database": {
      "main": [
        [
          {
            "node": "Risk Level Router",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Risk Level Router": {
      "main": [
        [
          {
            "node": "Build Critical Alert",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Build High Priority Alert",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Build Routine Reminder",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Build Routine Reminder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Critical Alert": {
      "main": [
        [
          {
            "node": "Send Critical Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build High Priority Alert": {
      "main": [
        [
          {
            "node": "Send High Priority Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Routine Reminder": {
      "main": [
        [
          {
            "node": "Send Routine Reminder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GPT-4o Mini": {
      "ai_languageModel": [
        [
          {
            "node": "Extract Visa Data",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "d58474f1-4fc7-4873-ad08-45b5d167a8cb",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "3a43da28588548e21903e71cf1dc3ddd65c24bf0c62e7e4b77542ffe87ad79c6"
  },
  "id": "mpH4bNOMtqKoBMGg",
  "tags": []
}